<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/30/030
 * Time: 15:10
 */

namespace Lib\Utils;


use Cache;
use Illuminate\Http\Request;

class CacheUtils
{
    public  static  $CACHE_TIME="CACHE_TIME";
    public  static  $DEFAULT_CACHE_TIME=60;
    public static function isCached($key){


        return Cache::get( $key)!=null;
    }
    public static function put($key,$data){
        Cache::put($key,$data,env(self::$CACHE_TIME,self::$DEFAULT_CACHE_TIME));
    }
    public static function put_by_minute($key,$data,$minute){
        Cache::put($key,$data,env(self::$CACHE_TIME,$minute));
    }
    public static function key(Request $request){
        $rd=$request->all();
        asort($rd);
        $key="#";
        foreach ($rd as $k => $d){
            $key=$key."_".$k."_".$d;
        }
        return $request->url().$key;
    }
    public static function key_by_ip(Request $request){
        $ip=$request->getClientIp();
        $rd=$request->all();
        asort($rd);
        $key="#".$ip;
        foreach ($rd as $k => $d){
            $key=$key."_".$k."_".$d;
        }
        return $request->url().$key;
    }
}